/**
 * Created by jianyijun on 2020/03/20.
 * WebApi通信fetch工具类
 */
import serverBase from './requestBase';

export default function fetchWebApi(eventUrl, data = {}, actionStyle) {

  // console.log("#### fetchWebApi ###");
  // console.log(data);

  return new Promise(resolve => {
    if (actionStyle == "GET") {
      resolve(serverBase.baseGet(eventUrl, data, data.token));
    } else if (actionStyle == "POST") {
      resolve(serverBase.basePost(eventUrl, data, data.token));
    } else if (actionStyle == "DELETE") {
      resolve(serverBase.baseDelete(eventUrl, data, data.token));
    } else if (actionStyle == "POSTWithQuery") {
      resolve(serverBase.basePostWithQuery(eventUrl, data, data.token));
    }
  });
}

export function fetchCatch(event, params) {
  return new Promise(resolve => {
    instance.emit(event, params, res => {
      resolve([res]);
    });
  });
}
